using System;
using System.Xml.Serialization;
using LockerRack.Helpers;

namespace TasksLib.DrawerStuff.Serializable
{
    public class SerializableTask
    {
        public SerializableTask()
        {
            IssueDate = DateTime.Now;
        }

        [XmlAttribute("Id")]
        public string Id
        {
            get { return GuidId.ToString(); }
            set
            {
                Guid g;
                if (Guid.TryParse(value, out g))
                {
                    GuidId = g;
                }
            }
        }

        [XmlAttribute("IsCompleted")]
        public bool IsCompleted;

        [XmlElement("Description")]
        public string Desc { get; set; }

        [XmlElement("Note")]
        public string Note { get; set; }

        [XmlElement("IssueDate")]
        public string IssueDateString
        {
            get { return IssueDate.ToiBwaveMobileString(); }
            set
            {
                Exception ex;
                var date = value.ToiBwaveMobileDate(out ex);
                if (ex == null)
                    IssueDate = date;
            }
        }

        private Guid _guidId;

        [XmlIgnore]
        public Guid GuidId
        {
            get
            {
                if (_guidId == Guid.Empty)
                    _guidId = Guid.NewGuid();

                return _guidId;
            }
            set { _guidId = value; }
        }

        [XmlIgnore]
        public DateTime IssueDate { get; set; }
    }
}